package com.balance.anole.erp.common.provider;

import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

import com.balance.anole.business.to.ProductColorTO;
import com.balance.anole.business.to.ProductSizeTO;
import com.balance.anole.erp.common.model.ProductItemVO;

public class ProductSelectorLabelProvider extends LabelProvider implements
		ITableLabelProvider, ITableColorProvider {
	private Color[] bg = new Color[]{new Color(null, 112,200,255), new Color(null, 247,247,240)};
    private Color[] force = new Color[]{new Color(null, 0,0,0), new Color(null, 0,0,0)};
    private Object current = null;
    private int currentColor = 0;

	public Image getColumnImage(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}

	public String getColumnText(Object element, int columnIndex) {
		ProductItemVO product = (ProductItemVO) element;
		switch (columnIndex) {
		case 0:
			return product.getSn();
		case 1:
			return product.getPdtDesc();
		case 2:
			ProductColorTO color = product.getColorTO();
			return color == null ? "" : color.getColorDesc();
		case 3:
			ProductSizeTO size = product.getSizeTO();
			return size == null ? "" : size.getSizeDesc();
		default: return "";
		}
	}

	public Color getBackground(Object element, int columnIndex) {
		  if (current != element) {
	            currentColor = 1 - currentColor;
	            current = element;
	        }
	        return bg[currentColor];
	}

	public Color getForeground(Object element, int columnIndex) {
		return force[currentColor];
	}

}
